package cn.edu.nju.oraldefense.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import cn.edu.nju.oraldefense.dao.DefenseDao;
import cn.edu.nju.oraldefense.model.Defense;

@Component("defenseDao")
public class DefenseDaoImpl implements DefenseDao {
	HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public void save(Defense instance) {
		hibernateTemplate.save(instance);
	}

	public Defense findById(int id) {
		Defense instance = (Defense) getHibernateTemplate().get(
				"cn.edu.nju.oraldefense.model.Defense", id);
		return instance;
	}

	public List findByProperty(String propertyName, Object value) {
		String queryString = "from Defense as model where model."
				+ propertyName + "=?";
		return hibernateTemplate.find(queryString, value);
	}

	public void update(Defense instance) {
		hibernateTemplate.update(instance);
	}

	public void delete(Defense instance) {
		hibernateTemplate.delete(instance);
	}

}
